﻿using System.Configuration;
using HRMSystemShi.DAL;
using Microsoft.Data.SqlClient;

namespace HRMSystemShi._2025
{
    public partial class Register : Form
    {
        public Register()
        {
            InitializeComponent();
        }

        private void buttonRegister_Click(object sender, EventArgs e)
        {
            string userName = textBoxUser.Text.Trim();
            string password = CommonHelper.GetMD5(textBoxPassword.Text.Trim());
            string realName = textBoxRealName.Text.Trim();
            string passwordCheck = CommonHelper.GetMD5(textBoxPasswordCheck.Text.Trim());

            if (userName.Length == 0 || password.Length == 0 || realName.Length == 0)
            {
                MessageBox.Show("用户名、密码、真实姓名不能为空", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (password != passwordCheck)
            {
                MessageBox.Show("两次输入的密码不一致", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

          
            string sql = "INSERT INTO Operator(UserName, Password, RealName,isDeleted,isLocked,isAdmin,id) VALUES(@UserName, @Password, @RealName,0,1,0,NEWID())";
            if (SqlHelper.ExecuteNonQuery(sql, new SqlParameter("@UserName", userName), new SqlParameter("@Password", password), new SqlParameter("@RealName", realName)) > 0)
            {

                MessageBox.Show("注册成功", "成功提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            FormLogin formLogin = new FormLogin();
            formLogin.ShowDialog();
            this.Close();

        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            FormLogin formLogin = new FormLogin();
            formLogin.ShowDialog();
            this.Close();
        }
    }
}
